package org.yagnus.stats.summary.univariate;

import java.util.Set;

import org.yagnus.langutils.BasicAccessibleMap;
import org.yagnus.langutils.mutables.MutableDouble;

public class DoubleHistogram<O> {
    BasicAccessibleMap<O, MutableDouble> bam = new BasicAccessibleMap<O, MutableDouble>(new MutableDouble(0)) {
        public MutableDouble allocate() {
            return new MutableDouble(0);
        }
    };

    public double add(O s) {
        return bam.getAllocate(s).inc();
    }

    public double add(O s, double v) {
        return bam.getAllocate(s).inc(v);
    }

    public double get(O s) {
        return bam.getWithDefault(s).get();
    }

    public Set<O> getAllValues() {
        return bam.keySet();
    }

    public int size() {
        return bam.size();
    }
}
